package com.level.game;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;

import com.engine.game.Event;
import com.engine.game.GameEngine;



public abstract class Configuration {
	
	protected GameEngine engine;
	
	protected ArrayList<Event> events;
	
	protected HashMap<String, ArrayList<Level>> mapOfStates;
	
	public String currentState;
	public int currentLevel;
	
	public Configuration(GameEngine engine){
		this.engine = engine;
		
		this.mapOfStates = new HashMap<String, ArrayList<Level>>();
		
		this.events = new ArrayList<Event>();
		
		this.createStates();
	}
	
	public void receiveMessage(Event event){
		
		
		events.add(event);
	}
	
	protected void clearEvents(){
		events.clear();
	}
	
	
	
	protected abstract void createStates();
	public abstract void setFirstState() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException;
	
	protected void addState(String name, ArrayList<Level> arr){
		this.mapOfStates.put(name, arr);
		
	}
	
	
	public abstract void update() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException;
	
	public void dispose(){
		this.clearEvents();
		this.events = null;
		
		for(String key : this.mapOfStates.keySet()){
			for(Level l : this.mapOfStates.get(key)){
				l.dispose();
			}
			this.mapOfStates.get(key).clear();
			
		}
		
		this.mapOfStates.clear();
		
		this.mapOfStates = null;
		
		
		this.currentState = null;
	}
	
}
